# -*- codeing = utf-8 -*-
# @Time : 2021/2/27 21:50
# @Atuthor: 朱朱
# @File: 142练习5.py
# @Software: PyCharm

class Student(object): # 学生类
    def __init__(self,number, name, age, gender, score): # 初始化变量
        self.number = number
        self.name = name
        self.age = age
        self.gender = gender
        self.score = score

    def __str__(self):
        return f'编号:{self.number},姓名:{self.name},' \
               f'年龄:{self.age},性别:{self.gender},分数:{self.score}'


class Grade(object):
    def __init__(self,name, students):
        self.name = name
        self.students = students

    def show_all(self):
        for student in self.students:
            print(student)

    def get_student_by_number(self,n):
        for s in self.students:
            if s.number == n:
                return s
        else:
            return '用户未找到'

    def failed_students(self):
        result = filter(lambda student: student.score < 60, self.students)
        for x in result:
            print(f'不及格的学生是:{x}')

    def order_students(self):
        return sorted(self.students, key=lambda s: s.score, reverse=True)

s1 = Student('001', 'jack', 18, 'male', 80)
s2 = Student('005','tony',19,'male',50)
s3 = Student('010','tom',20,'male',70)
s4 = Student('007','luck',22,'female',90)
s5 = Student('004','lina',19,'female',56)

g = Grade('中二班',[s1,s2,s3,s4,s5])
g.show_all()
print('---------------------')
g.failed_students()
print('----------------')
s = g.order_students()
for student in s:
    print(student)
print('--------------------')
print(g.get_student_by_number('001'))
print(g.get_student_by_number('009'))
